package com.java.cas;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @author wangning
 * @date 2023/5/12 15:13
 */
public class AtomicReferenceDemo {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger();
        //例如User/Order/...
        AtomicReference<User> atomicReference = new AtomicReference<>();
        User user1 = new User("张三");
        User user2 = new User("李四");
        atomicReference.set(user1);
        System.out.println(atomicReference.compareAndSet(user1, user2) + "\t" + atomicReference.get().getName());
        System.out.println(atomicReference.compareAndSet(user1, user2) + "\t" + atomicReference.get().getName());

    }
}

class User {
    String name;

    public User(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
